package com.ruoyi.web.controller.system;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SportStadiumPojo;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.mapper.SportStadiumMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author czg
 * @date 2021/9/27 10:32 下午
 */
@Api(tags = "体育场馆预约服务")
@RestController
@RequestMapping("/api/sportStadium")
public class SportStadiumController {

    @Autowired
    SportStadiumMapper sportStadiumMapper;


    @PostMapping("/list")
    @ApiOperation("体育场馆列表")
    public AjaxResult<List<SportStadiumPojo>> listSportStadium(@RequestBody SportStadiumPojo sportStadiumPojo) {

        QueryWrapper<SportStadiumPojo> query = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(sportStadiumPojo.getName())) {
            query.eq("name", sportStadiumPojo.getName());
        }
        if (StringUtils.isNotEmpty(sportStadiumPojo.getLocation())) {
            query.eq("location", sportStadiumPojo.getLocation());
        }
        if (StringUtils.isNotEmpty(sportStadiumPojo.getCampus())) {
            query.eq("campus", sportStadiumPojo.getCampus());
        }
        if (sportStadiumPojo.getStatus() != null) {
            query.eq("status", sportStadiumPojo.getStatus());
        }
        return AjaxResult.success(sportStadiumMapper.selectList(query));
    }

    @PostMapping("/add")
    @ApiOperation("新增体育场馆")
    public AjaxResult addSportStadium(@RequestBody SportStadiumPojo schoolAreaPojo) {
        sportStadiumMapper.insert(schoolAreaPojo);
        return AjaxResult.success();
    }


    @PutMapping("/update")
    @ApiOperation("修改体育场馆")
    public AjaxResult updateSportStadium(@RequestBody SportStadiumPojo schoolAreaPojo) {
        sportStadiumMapper.updateById(schoolAreaPojo);
        return AjaxResult.success();
    }


    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除体育场馆")
    public AjaxResult deleteSportStadium(@PathVariable Integer id) {
        sportStadiumMapper.deleteById(id);
        return AjaxResult.success();
    }

    @GetMapping("/list/xuhui")
    @ApiOperation("徐汇校区可预约体育场馆")
    public AjaxResult<List<SportStadiumPojo>> listStudyRoom1(@ApiParam(value = "场馆类型（sport->功能场馆; party->活动室）") String type) {
        if (StringUtils.isBlank(type)) {
            type = "sport";
        }
        QueryWrapper<SportStadiumPojo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("campus", "徐汇校区");
        queryWrapper.eq("type", type);
        return AjaxResult.success(sportStadiumMapper.selectList(queryWrapper));
    }

    @GetMapping("/list/fengxian")
    @ApiOperation("奉贤校区可预约体育场馆")
    public AjaxResult<List<SportStadiumPojo>> listStudyRoom2(@ApiParam(value = "场馆类型（sport->功能场馆; party->活动室）") String type) {
        if (StringUtils.isBlank(type)) {
            type = "sport";
        }
        QueryWrapper<SportStadiumPojo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("campus", "奉贤校区");
        queryWrapper.eq("type", type);
        return AjaxResult.success(sportStadiumMapper.selectList(queryWrapper));
    }
}
